import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p004 from './p004';

import format from '@dfeidao/atom-web/dt/format';
/** 技术排序 */
export default async function a020(fd: IFeidaoAiBrowserComponent, e: Event) {
	// todo
	const i = e.currentTarget as HTMLElement;
	const datav = i.getAttribute('data-v');
	const datano = i.getAttribute('data-no');

	if (datano === "0") {
		const res = await nodejs<{ da2: Array<{ create_time: number }> }>('knowledge-base/zj-000001/s010', {
			filter: {
				data_v: datav
			}
		});
		const da2 = res.da2.map((n) => {
			return { ...n, create_time: format(n.create_time, 2) };
		});

		render(fd, da2, p004, 'p004', 'inner');
		i.setAttribute('data-no', '1');
	}
	if (datano === "1") {
		const res = await nodejs<{ dc2: Array<{ create_time: number }> }>('knowledge-base/zj-000001/s010', {
			filter: {
				data_v: datav
			}
		});
		const dc2 = res.dc2.map((n) => {
			return { ...n, create_time: format(n.create_time, 2) };
		});

		render(fd, dc2, p004, 'p004', 'inner');
		i.setAttribute('data-no', '0');
	}
}
